<template>
<div class="coupon-client views-container">
    <div class="wlm-table no-bg">
        <div class="wlm-table-content">
            <el-carousel ref="carousel" arrow="never" class="wlm-carousel" :autoplay="false" indicator-position="none" trigger="click" height="130px">
                <el-carousel-item v-for="item in platformList" :key="item.name" :name="item.name">
                    <el-row :gutter="20">
                        <el-col :span="6">
                            <div class="plugin-item flex-row">
                                <!-- <div class="svg-container flex-col flex-align-c flex-justify-c" style="padding-right:14px">
                                  <div class="svg-box"><svg-icon  icon-class="ClientNew" /></div>
                                </div> -->
                                <img class="svg-box" src="@/assets/couponClient/new.png" alt="">
                                <div class="flex-col scale-grow" style="position: relative;">
                                    <div>
                                        <div class="flex-row flex-justify-b">
                                            <div class="item-title">新客进店有礼</div>
                                            <div>
                                                <router-link tag="span" to="/application/couponClientNew">
                                                    <el-button type="primary" size="small">新建</el-button>
                                                </router-link>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="item-text">新客进店，赠送专享礼包，拉新从此有的放矢。</div>
                                </div>
                            </div>
                        </el-col>
                        <el-col :span="6">
                            <div class="plugin-item flex-row">
                                <img class="svg-box" src="@/assets/couponClient/old.png" alt="">
                                <div class="flex-col scale-grow" style="position: relative;">
                                    <div>
                                        <div class="flex-row flex-justify-b">
                                            <div class="item-title">老客进店有礼</div>
                                            <div>
                                                <router-link tag="span" to="/application/couponClientOld">
                                                    <el-button type="primary" size="small">新建</el-button>
                                                </router-link>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="item-text">老客进店，赠送专享礼包，提升复购率。</div>
                                </div>
                            </div>
                        </el-col>
                        <el-col :span="6">
                            <div class="plugin-item flex-row">
                                <img class="svg-box" src="@/assets/couponClient/Fixed.png" alt="">
                                <div class="flex-col scale-grow" style="position: relative;">
                                    <div>
                                        <div class="flex-row flex-justify-b">
                                            <div class="item-title">定向发券</div>
                                            <div>
                                                <router-link tag="span" to="/application/couponClientFixed">
                                                    <el-button type="primary" size="small">新建</el-button>
                                                </router-link>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="item-text">智能筛选目标用户，并给这些用户一键群发优惠券。</div>
                                </div>
                            </div>
                        </el-col>
                        <el-col :span="6">
                            <div class="plugin-item flex-row">
                                <img class="svg-box" src="@/assets/couponClient/Fissure.png" alt="">
                                <div class="flex-col scale-grow" style="position: relative;">
                                    <div>
                                        <div class="flex-row flex-justify-b">
                                            <div class="item-title">关注收藏有礼</div>
                                            <div>
                                                <router-link tag="span" to="/application/couponClientFissure">
                                                    <el-button type="primary" size="small">新建</el-button>
                                                </router-link>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="item-text">关注公众号或收藏小程序，赠送大礼包，留存粉丝</div>
                                </div>
                            </div>
                        </el-col>
                    </el-row>
                </el-carousel-item>
            </el-carousel>
        </div>
    </div>
    <div class="wlm-table">
        <div class="wlm-table-content">
            <!-- {{$store.getters.sotreName}} -->
            <el-tabs v-model="tableFormatData.couponmarketing.files.voucher_type" type="card" @tab-click="filesSerch">
                <el-tab-pane label="新客进店有礼" name="1"></el-tab-pane>
                <el-tab-pane label="老客进店有礼" name="2"></el-tab-pane>
                <el-tab-pane label="定向发券" name="3"></el-tab-pane>
                <el-tab-pane label="关注收藏有礼" name="[5,6]"></el-tab-pane>
            </el-tabs>
            <el-table v-loading="!isTableFormatGetEnd" :ref="tableFormatData.couponmarketing.key" :data="tableFormatData.couponmarketing.tableData" @selection-change="handleSelectionChange" style="width: 100%">
                <el-table-column type="selection" width="55">
                </el-table-column>
                <el-table-column label="活动名称" >
                    <template slot-scope="scope">
                        <p>{{scope.row.voucher_title}}</p>
                    </template>
                </el-table-column>
                <template v-if="tableFormatData.couponmarketing.files.voucher_type=='1'||tableFormatData.couponmarketing.files.voucher_type=='2'||tableFormatData.couponmarketing.files.voucher_type=='[5,6]'">

                    <el-table-column label="开始时间" >
                        <template slot-scope="scope">
                            <span>{{scope.row.voucher_start_time*1000 | parseTime('{y}-{m}-{d} {h}:{i}:{s}')}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="结束时间"  >
                        <template slot-scope="scope">
                            <span>{{scope.row.voucher_end_time*1000 | parseTime('{y}-{m}-{d} {h}:{i}:{s}')}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="领取人数" >
                        <template slot-scope="scope">
                            <span>{{scope.row.number}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="活动状态" >
                        <template slot-scope="scope">
                            <span>{{coupon_status[`${scope.row.voucher_state}`]}}</span>
                        </template>
                    </el-table-column>
                </template>
                <template v-if="tableFormatData.couponmarketing.files.voucher_type=='3'">
                    <el-table-column label="目标人群"  >
                        <template slot-scope="scope">
                            <span>{{coupon_crowd[`${scope.row.voucher_crowd}`]}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="投放人数"  >
                        <template slot-scope="scope">
                            <span>{{scope.row.success_number}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="发券进度"  >
                        <template slot-scope="scope">
                            <span>{{getPercent(scope.row.number,scope.row.success_number)}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="成功发放"  >
                        <template slot-scope="scope">
                            <span>{{scope.row.number}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="开始发券时间"  >
                        <template slot-scope="scope">
                            <span>{{scope.row.create_time}}</span>
                        </template>
                    </el-table-column>
                </template>
                <el-table-column min-width="120" label="操作"  width="290">
                    <template slot-scope="scope">
                        <div class="operation-group">
                            <router-link class="wlm-text" tag="div" :to="{path:voucher_type_path[`${scope.row.voucher_type}`], query :{ voucher_id : scope.row.voucher_id}}">
                                <el-button type="text">{{scope.row.voucher_type == '3'?'查看':'编辑'}}</el-button>
                            </router-link>
                            <div v-if="scope.row.voucher_state==2||scope.row.voucher_state==3" class="btn-line"></div>
                            <el-button v-if="scope.row.voucher_state==2" class="wlm-text" type="text" @click="changeTableItem({ids:[scope.row.voucher_id],is_stop:3},tableFormatData.couponmarketing.change.stop)">暂停</el-button>
                            <el-button v-if="scope.row.voucher_state==3" class="wlm-text" type="text" @click="changeTableItem({ids:[scope.row.voucher_id],is_stop:2},tableFormatData.couponmarketing.change.stop)">开始</el-button>
                            <div class="btn-line"></div>
                            <el-button class="wlm-text" type="text" @click="delTableItem(scope.row.voucher_id)">删除</el-button>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-content flex-row flex-justify-b flex-align-c">
                <el-row class="pagination-btns">
                    <el-checkbox class="check-all" true-label="1" false-label="0" v-model="tableFormatData.couponmarketing.files.checkall" @change="toggleSelection">全部</el-checkbox>
                    <el-button class="right-8" :disabled="isGroup" size="mini" @click="delTableList">删除</el-button>
                </el-row>
                <el-pagination :disabled="!hasTableData" @size-change="listPageChange" @current-change="listPageChange" :current-page.sync="tableFormatData.couponmarketing.pagination.page" :page-sizes="tableFormatData.couponmarketing.pagination.pagesizes" :page-size.sync="tableFormatData.couponmarketing.pagination.list_rows" layout="total, sizes, prev, pager, next, jumper" :total="hasTableData?tableFormatData.couponmarketing.pagination.total : 0">
                </el-pagination>
            </div>
        </div>
    </div>
</div>
</template>

<script>
import {
  voucherLists,
  voucherDestroy,
  voucherIsStop
} from '@/api/application'
import mixins from '@/mixins/mixins'
import ShareLink from '@/components/ShareLink/index'
export default {
  mixins: [mixins.getters('Table')],
  name: 'CouponClient',
  components: {
    ShareLink,
    couponRender: {
      template: '<span><slot name="title"></slot><span class="text-danger"><slot name="price"></slot></span><slot name="tail"></slot></span>'
    }
  },
  data() {
    return {
      dialogTableVisible: false,
      changeType: false,
      platformList: [{
        name: 'shang',
        data: []
      }],
      coupon_status: {
        '1': '未开始',
        '2': '进行中',
        '3': '已暂停',
        '4': '已结束',
        '-1': '定向发送'
      },
      coupon_crowd: {
        '1': '意向客户',
        '2': '流失客户',
        '3': '选择用户',
        '4': '指定商品',
        '5': '自定义',
        '6': '选择用户标签'
      },
      voucher_type: {
        10: '满减券',
        20: '折扣券',
        30: '运费券',
        40: '随机券'
      },
      coupon_price: {
        10: {
          textRule: '满',
          textPrev: '减免',
          textLast: '元'
        },
        20: {
          textRule: '满',
          textPrev: '打',
          textLast: '折'
        },
        30: {
          textRule: '满',
          textPrev: '减免',
          textLast: '元'
        },
        40: {
          textRule: '满',
          textPrev: '范围内随机',
          textLast: '元'
        }
      },
      voucher_type_path: {
        '1': '/application/couponClientNew',
        '2': '/application/couponClientOld',
        '3': '/application/couponClientFixed',
        '5': '/application/couponClientFissure',
        '6': '/application/couponClientFissure'
      },
      tableFormatData: {
        current: 'couponmarketing',
        couponmarketing: {
          key: 'couponmarketing',
          api: {
            getList: voucherLists,
            delList: voucherDestroy
          },
          tableData: [],
          files: {
            ids: [],
            checkall: '0',
            Recycle: '1',
            voucher_type: '1',
            redirect: 'voucher_id'
          },
          change: {
            stop: {
              name: '停止',
              key: 'stop',
              api: voucherIsStop
            }
          },
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          }
        }
      }
    }
  },
  //   created() {
  //     this.$store.dispatch('callSetName', 2)
  //   },
  methods: {
    getPercent(num, total) {
    // / <summary>
    // / 求百分比
    // / </summary>
    // / <param name="num">当前数</param>
    // / <param name="total">总数</param>
      num = parseFloat(num)
      total = parseFloat(total)
      if (isNaN(num) || isNaN(total)) {
        return '-'
      }
      return total <= 0 ? '0%' : (Math.round(num / total * 10000) / 100.00) + '%'
    }
  }
}
</script>

<style lang="scss" scoped>
.coupon-client {
    font-size: 14px;

    .svg-box {
        border-radius: 50%;
        height: 50px;
        width: 50px;
        overflow: hidden;
        margin-right: 6px;
    }

    .svg-container svg {
        padding: 12px;
        background: #409EFF;
        fill: #ffffff;
        font-size: 50px;
    }

    .plugin-item {
        height: 130px;
        border: 1px solid rgb(236, 236, 236);
        background-color: #ffffff;
        padding: 24px 20px;
        border-radius: 3px;

        .item-title {
            font-size: 16px;
            font-weight: 600;
        }

        .item-text {
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
            overflow: hidden;
            text-overflow: ellipsis;
            margin-top: 8px;
        }
    }
}
</style>
